<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<base href="<%=basePath%>">
<title>YP.ShO购</title>
<link rel="stylesheet" href="css/bootstrap.css"></link>
<link rel="stylesheet" href="css/style.css"></link>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easydropdown.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
</script>
<style type="text/css">
.form p {
	margin-bottom: 15px;
}

.form label {
	width: 8em;
}
		table{
			width:100%;
			border-color:#dd8800;
			border-collapse: collapse;
			margin:5px 0 5px 0;
		}
		table tr td{
			border:1px solid;
			border-color: #DAB69C;
			text-align:center;
		}
		table thead td{
			background-color: #DAB69C;
			height:50px;
		}
		table tbody td{
			height:100px;
			border-collapse: collapse;
			border-width: 0px 1px 1px 1px;
			border-color: #DAB69C;
		}
</style>
</head>
	<body>
		<%@include file="../common/head.jsp"%>
		<div class="menu"></div>
		<div class="men">
			<div class="container">
				<div class="col-md-3 sidebar">
					<div class="block block-layered-nav">
						<div class="block-title">
							<strong><span>我的YPShO购</span></strong>
						</div>
					<div class="block-content">
						<dl id="narrow-by-list">
							<dt class="last odd">用户中心</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userInforView">个人信息管理</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是买家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userOrders" style="color:#e05b5b">我的订单管理</a></li>
									<li><a href="userCart">我的购物车</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是卖家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="sellerOrders">我的订单管理</a></li>
									<li><a href="sellerGoods">我的商品管理</a></li>
								</ol>
							</dd>
						</dl>
					</div>
				</div>
				</div>
				<div class="col-md-9">
					<div class="mens-toolbar">
						<div class="sort">
							<div class="sort-by">
								<label>我的订单管理</label>
							</div>
						</div>
					</div>
					<div class="form">
					<!-- <table>
						<tr>
							<th>订单状态</th>
							<th>订单号</th>
							<th>总金额</th>
						</tr>
						<s:iterator value="Olist" id="orders">
							<tr>
								<td><s:property value="#orders.status" />
								<td><s:property value="#orders.id" />
								<td><s:property value="#orders.money" />
							</tr>
						</s:iterator>
						</table>-->
						<!-- 用于放订单的div -->
						<div id="userOrders">
							<!-- <table>
								<thead>
									<tr>
										<td>2017-04-09</td>
										<td>订单号: 201704091156130019</td>
										<td colspan="5">酱油之道</td>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td style="border-right:0px"><img src="http://b.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=f0c5c08030d3d539c16807c70fb7c566/8ad4b31c8701a18bbef9f231982f07082838feba.jpg" style="width:60px;height:60px"/></td>
										<td style="border-left:0px">
											商品名
										</td>
										<td>单价100$</td>
										<td >数量3</td>
										<td>总价300$</td>
										<td>已付款</td>
										<td><input type="button" value="去付款"/></td>
									</tr>
								</tbody>
							</table>-->
						</div>
					
					</div>
				</div>
			</div>
		</div>
		<%@include file="../common/footer.jsp"%>
	</body>
	<script type="text/javascript">
		function payFromeUserOrder(orderNum){
			window.location.href = "<%=basePath%>payFromeUserOrder.action?orderNum="+orderNum;
		}
		
		function confirmPayOrder(orderNum) {
			window.location.href = "<%=basePath%>confirmPayOrder.action?orderNum="+orderNum;
		}
		$(document).ready(function(){
			getOrders();
		});
		//获取订单
		function getOrders(){
			$.ajax({
				url:"getUserOrders.action",
				type:"post",
				data:{},
				dataType:"json",
				success:function(data){
					//console.log(data);
					var datas = eval(data);
					
					if(datas.result.length > 0){
						var ordersStr = "";
						
						for(var i=0;i<datas.result.length;i++){
							var o = datas.result[i];
							var orderStr = "<table>";
							orderStr += "<thead><tr>";
							orderStr += "<td width=\"15%\">" + o.createDate + "</td>";
							orderStr += "<td width=\"35%\">订单号:" + o.orderNo + "</td>";
							orderStr += "<td colspan=\"5\" width=\"50%\">" + o.seller + "</td>";
							orderStr += "</tr>";
							orderStr += "</thead><tbody>";
							if(o.goods.length > 0){//遍历商品开始
								var isStatusWritten = false;
								for(var j=0;j<o.goods.length;j++){
									var g = o.goods[j];
									orderStr += "<tr><td style=\"border-right:0px\" width=\"5%\"><img src=\""+g.img+"\" style=\"width:60px;height:60px\"/></td>";	//商品图片
									orderStr += "<td style=\"border-left:0px\" width=\"35%\">" + g.name + "</td>"	//商品名称
									orderStr += "<td width=\"5%\">" + g.price + "￥</td>"		//价格
									orderStr += "<td width=\"5%\">" + g.amount + "</td>"	//数量
									//此处开始写订单总价, 状态和可操作行为
									if(!isStatusWritten){
										var rowspanStr = "";
										if(o.goods.length > 1){//如果该订单只有一件商品
											rowspanStr = "rowspan=\"" + o.goods.length + "\"";
										}
										
										orderStr += "<td "+rowspanStr+" width=\"5%\">" + o.totalPrice + "￥</td>";//订单总价
										orderStr += "<td "+rowspanStr+" width=\"25%\">" + o.status + "</td>";	//订单当前状态
										//订单可操作行为
										var avaliableActions = o.avaliableStatus.split("-");
										if(avaliableActions[1] == "false"){//如果当前为不显示任何
											orderStr += "<td "+rowspanStr+" width=\"20%\"></td>";
										}else{
											if(avaliableActions[0] == "付款"){
												orderStr += "<td "+rowspanStr+" width=\"20%\"><input type=\"button\" value=\"" + avaliableActions[0] + "\" onclick=\"payFromeUserOrder('" + o.orderNo + "')\" /></td>";
											}
											if(avaliableActions[0] == "确认收货"){
												orderStr += "<td "+rowspanStr+" width=\"20%\"><input type=\"button\" value=\"" + avaliableActions[0] + "\" onclick=\"confirmPayOrder('" + o.orderNo + "')\" /></td>";
											}
										}
										isStatusWritten = true;
									}
									orderStr += "</tr>";
								}
							}
							orderStr += "</tbody></table>";
							ordersStr += orderStr;
						}
						$("#userOrders").html(ordersStr);
					}
				},
				
			})
		}
	</script>
</html>